<template>
	<view class="content" >
		<view class="navTabBox">
			<view class="longTab">
				<scroll-view scroll-x="true" style="white-space: nowrap; display: flex;width: 100%;" scroll-with-animation>
					<view class="longItem" style="width:50%" v-for="(item,index) in tabTitle" :key="index">
						<view class="" :data-index="index"  :id="'id'+index" @click="longClick(item.id)">{{item.name}}</view>
						<view class="underlineBox">
							<view class="underline" :class="active == item.id ? 'bgcolor' :''"></view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
		 
		<view class="video" v-if="active == 1">
			<view class="video_item" v-for="(item, index) in videolist" :key="index" @click="videoDetial(item.id)"  >
				<image :src="ajax + item.image"></image>
				<!-- <image src="../../../static/yaoqing.png"></image> -->
				<view class="vide">
					<text class="vid iconfont icon-bofang"></text>
				</view>
				<view class="video_text">{{item.name}}<text class="more iconfont icon-ziyuan"></text></view>
			</view>
		</view>
		<view class="wu" v-if="videolist.length == 0">暂无数据~</view> 
		
		<view class="video" v-if="active == 2">
			<view class="video_item" v-for="(item, index) in xslist" :key="index" @click="xsDetial(item.id,item.section_id)"  >
				<!-- <image src="../../../static/yaoqing.png"></image> -->
				<image :src="ajax + item.image"></image>
				<view class="video_text">{{item.name}}<text class="more iconfont icon-ziyuan"></text></view>
			</view>
		</view>
		<view class="wu" v-if="xslist.length == 0">暂无数据~</view> 
	</view>
</template>

<script>
import getdata from '@/common/ajax.js';	
import uniLoadMore from '@/components/uni-load-more.vue';
var
	page = 1,
	timer = null,
	pages = 1;
	export default {
		components: {uniLoadMore},
		data() {
			return {
				tabTitle: [{
					name: '视频',
					id: 1
				},  {
					name: '小说',
					id: 2
				}],
				active: 1,
				videolist:[],
				xslist:[],
				loadingText: '加载中...',
				ajax:''
			}
		},
		onLoad() {
			this.shipin()
			this.ajax = getdata.imgUrl
		},
		methods: {
			longClick(index) { 
				var _this = this
				this.active = index
				// uni.stopPullDownRefresh(); //得到数据后停止下拉刷新
				if(index == 1){
					_this.shipin()
				}else{
					_this.xiaoshuo()
				}
			}, 
			shipin(){
				uni.showLoading({
				    title: '加载中'
				});
				var _this = this
				var token = uni.getStorageSync('token')
				uni.request({
					url: getdata.websiteUrl + '/movie/my_movie',
					header:{'content-type': "application/x-www-form-urlencoded",token:token},
					dataType: 'json',
					method: 'POST',
					success: res => {
						uni.hideLoading();
						console.log(res,'视频')
						if(res.data.code == 1){
							_this.videolist = res.data.data
						}else{
							getdata.shou(res.data.msg)
						}
					},
					fail: res => {
						uni.hideLoading();
						getdata.shou('服务器断开链接')
					}
				});
			},
			xiaoshuo(){
				uni.showLoading({
				    title: '加载中'
				});
				var _this = this
				var token = uni.getStorageSync('token')
				uni.request({
					url: getdata.websiteUrl + '/novel/my_novel',
					header:{'content-type': "application/x-www-form-urlencoded",token:token},
					dataType: 'json',
					method: 'POST',
					success: res => {
						uni.hideLoading();
						console.log(res,'小说')
						if(res.data.code == 1){
							_this.xslist = res.data.data
						}else{
							getdata.shou(res.data.msg)
						}
					},
					fail: res => {
						uni.hideLoading();
						getdata.shou('服务器断开链接')
					}
				});
			},
			videoDetial(id){
				uni.navigateTo({
					url:'../../index/video/video?id=' + id 
				})
			}, 
			xsDetial(id,id1){
				uni.navigateTo({
					url:'../../xiaoshuo/xsdetail/xsdetail?id=' + id + '&novel_id=' + id1
				})
			},
		}
	}
</script>

<style lang="scss">
@import '../../../static/iconfont/iconfont.css';	
.bgcolor {
	background: #1578F2;
}
.wu{
	text-align: center;
	font-size: 30rpx;
	color: #8D8D97;
}
.color {
	// color: #1578F2 !important;
}	
.video{
	width: 100%;
	box-sizing: border-box;	
	display: flex;
	justify-content: space-between;
	flex-wrap: wrap;
	padding:30rpx;
	.video_item{
		width: 342rpx;
		height: 430rpx;
		border-radius: 10rpx;
		// background-color: #007AFF;
		margin-bottom: 10rpx;
		position: relative;
		image{
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}
		.vide{
			position: absolute;
			right:0;
			top:18rpx;
			width: 42rpx;
			height: 42rpx;
			line-height: 34rpx;
			background: rgba(0, 0, 0, 0.4);
			border-radius: 20rpx 0px 0px 20rpx;
			.vid{
				color: #fff;
				margin-left: 5rpx;
				font-size: 30rpx;
			}
		}
		.video_text{
			width: 342rpx;
			height: 90rpx;
			line-height: 90rpx;
			border-radius: 0px 0px 10rpx 10rpx;
			box-sizing: border-box;	
			padding-left:40rpx;
			padding-right:20rpx;
			font-size: 24rpx;
			font-weight: bold;
			color: #FFFFFF;
			position: absolute;
			bottom:0;
			left:0;
			overflow: hidden;
			text-overflow:ellipsis;
			white-space: nowrap;
			.more{
				position: absolute;
				bottom:0;
				right:0;
			}
		}
	}
}
// 导航切换
.navTabBox {
		width: 100vw;
		color: black;
		font-size: 30rpx;

		.click {
			color: #2CB5A9;
		}

		.longTab {
			width: 100%;
			box-sizing: border-box;
			font-size: 28rpx;
			.longItem {
				width: 100%;
				height: 70upx;
				display: inline-block;
				line-height: 70upx;
				text-align: center;
				margin-top: 10rpx;
				box-sizing: border-box;
				padding: 0 30rpx;
				.underlineBox {
					height: 4rpx;
					width: 18%;
					margin: 0 auto;
					display: flex;
					align-content: center;
					justify-content: center;
					transition: .5s;

					.underline {
						width: 84upx;
						height: 4px;

					}
				}
			}

		}
	}	
</style>
